<script>
/*
* print user_name's error info when update fails
*/
function updateErrInfo(data)
{
	var element=document.getElementById('user_name');
	element.innerHTML=data;
}
</script>

<?php $profile_form = $this->beginWidget('CActiveForm', array(
		'id'=>'profile-form',
		'enableClientValidation'=>true,
	//	'enableAjaxValidation'=>true,
		));
?>

	<div align="right" style="color:#FF0000">
	<label id='user_name'></label>
	<?php echo $profile_form->error($model, "user_name") ?>
	<?php echo $profile_form->error($model, "password"); ?>
	<?php echo $profile_form->error($model, "password2"); ?>
	<?php echo $profile_form->error($model, "address1"); ?>
	<?php echo $profile_form->error($model, "city"); ?>
	<?php echo $profile_form->error($model, "state"); ?>
	<?php echo $profile_form->error($model, "zip"); ?>
	<?php echo $profile_form->error($model, "contact_first_name"); ?>
	<?php echo $profile_form->error($model, "phoneNumber"); ?>
	<?php echo $profile_form->error($model, "emailAddress"); ?>
	</div>
  	<table width="100%" border="0" cellspacing="0" cellpadding="0">
  		<tr>
			<th width="64">USERNAME</th>
			<td>
				<div class="rstep2-box">
					<?php echo $profile_form->textField($model, 'user_name', array(
																'value'=>$row['user_name'],
																'ajax'=>array( 
																	'type'=>'POST',
																	'url'=>CController::createUrl('admin/checkValid'),
																	'success'=>'updateErrInfo',
																),
																'onchange'=>'changeStatus(DOMAIN.PROFILE, STATUS.CHANGED)',
															)); ?>
				</div>
			</td>
		</tr>
		<tr>
			<th>PASSWORD</th>
			<td>
			<div class="rstep2-box">
				<?php echo $profile_form->passwordField($model, 'password', array('onchange'=>'changeStatus(DOMAIN.PROFILE, STATUS.CHANGED)')); ?>
			</div>
			</td>
		</tr>
		<tr>
			<th>RETYPE PASSWORD</th>
			<td>
			<div class="rstep2-box">
				<?php echo $profile_form->passwordField($model, 'password2', array('onchange'=>'changeStatus(DOMAIN.PROFILE, STATUS.CHANGED)')); ?>
			</div>
			</td>
		</tr>
		<tr>
    		<th>BILLING ADDRESS</th>
    		<td>
    		<div class="rstep1-box5">
    			<?php echo $profile_form->textField($model, 'address1', array('value'=>$row['address1'],'onchange'=>'changeStatus(DOMAIN.PROFILE, STATUS.CHANGED)')); ?>
    		</div>
    		</td>
    	</tr>
    	<tr>
          	<th>CITY</th>
          	<td width="209">
         	<div class="rstep1-box2">
				<?php echo $profile_form->textField($model, 'city', array('value'=>$row['city'],'onchange'=>'changeStatus(DOMAIN.PROFILE, STATUS.CHANGED)')); ?>
         	</div>
          	</td>
         </tr>
         <tr>
          	<th>STATE</th>
          	<td>
         	<div class="state"><select name="Users[state]">
			  	<?php 
			  	$states = USStates::model()->getAllStates();
			  	foreach ($states as $state) { 
		          	if ($row['state'] == $state->abbreviation_name)
		          		$selected = "SELECTED";
		          	else
		          		$selected = '';
		          	echo '<option '.$selected.'>'.$state->abbreviation_name.'</option>';
	          	} 
	          	?>
		  	</select></div>
		  	</td>
		 </tr>
		 <tr>
          	<th>ZIP</th>
          	<td>
         	<div class="rstep1-box4">
          		<?php echo $profile_form->textField($model, 'zip', array('value'=>$row['zip'],'onchange'=>'changeStatus(DOMAIN.PROFILE, STATUS.CHANGED)')); ?>
         	</div>
          	</td>
         </tr>
         <tr>
          	<th>FIRST NAME</th>
	    	<td>
	    	<div class="rstep1-box5">
	    		<?php echo $profile_form->textField($model, 'contact_first_name', array('value'=>$row['contact_first_name'],'onchange'=>'changeStatus(DOMAIN.PROFILE, STATUS.CHANGED)')); ?>
	    	</div>
	    	</td>
	     </tr>
	     <tr>
          	<th>LAST NAME</th>
	    	<td>
	    	<div class="rstep1-box5">
	    		<?php echo $profile_form->textField($model, 'contact_last_name', array('value'=>$row['contact_last_name'],'onchange'=>'changeStatus(DOMAIN.PROFILE, STATUS.CHANGED)')); ?>
	    	</div>
	    	</td>
	     </tr>
	     <tr>
	    	<th>PHONE #</th>
    		<td>
    		<div class="rstep1-box5">
    			<?php echo $profile_form->textField($model, 'phoneNumber', array('value'=>$row['phoneNumber'],'onchange'=>'changeStatus(DOMAIN.PROFILE, STATUS.CHANGED)')); ?>
    		</div>
    		</td>
    	 </tr>
    	 <tr>
    		<th>EMAIL ADDRESS</th>
    		<td>
    		<div class="rstep1-box5">
				<?php echo $profile_form->textField($model, 'emailAddress', array('value'=>$row['emailAddress'],'onchange'=>'changeStatus(DOMAIN.PROFILE, STATUS.CHANGED)')); ?>
    		</div>
    		</td>
  		 </tr>
 </table>
 
 <div align='center'>
 	<?php echo CHtml::imageButton(Yii::app()->request->baseUrl.'/images/submit.jpg', array(
										'ajax'=>array(				
											'type'=>'POST',
											'url'=>CController::createUrl('admin/profile'),
											'success'=>'updateStatus',
											'dataType'=>'json',
										),
									)
								); ?>
 </div>
 
<?php $this->endWidget();?>